package commonUse

import (
	"fmt"
	"time"
)

func BlockTest1() {
	ch := make(chan int)
	go startSBlockTestendChanFun(ch)

	fmt.Printf("test 1, run end %d\n", <-ch)
}

func recvchan(ch <-chan int) {
	fmt.Printf("test 2, run end %d\n", <-ch)
}

func BlockTest2() {
	ch := make(chan int)
	go startSBlockTestendChanFun(ch)
	recvchan(ch)
}

func recvchanValue(value int) {
	fmt.Printf("test 3, run end %d\n", value)
}

func BlockTest3() {
	ch := make(chan int)
	go startSBlockTestendChanFun(ch)
	recvchanValue(<-ch)
}

// 上面3个 BlockTestX 打印，都会等 startSBlockTestendChanFun中的发送而阻塞

func startSBlockTestendChanFun(ch chan<- int) {
	time.Sleep(5 * time.Second)
	ch <- 3
}
